package com.lzxuni.controller;

import com.lzxuni.po.QxDataCostom;
import com.lzxuni.service.CreateTableService;
import com.lzxuni.service.QxDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@RequestMapping("/createTable")
@RestController
public class CreateTableController {
    @Autowired
    private CreateTableService createTableService;
    @Autowired
    private QxDataService qxDataService;

    @RequestMapping("/createTable.html")
    public void create(String userkey,String data,String date) throws Exception {
        QxDataCostom qxDataCostom = new QxDataCostom();
        List<QxDataCostom> list = qxDataService.findQxDataList(qxDataCostom);
        for (int i = 0; i < list.size(); i++) {
            userkey = list.get(i).getUserkey();
            data =  list.get(i).getKqwd() + "," + list.get(i).getKqsd() + "," + list.get(i).getGz() + "," + list.get(i).getTrwd() + "," + list.get(i).getTrsd() + "," + list.get(i).getFs() + "," + list.get(i).getFx() + "," + list.get(i).getEyht() + "," + list.get(i).getYl();
            Date currentTime = list.get(i).getCreateTime();
            SimpleDateFormat formatter = new SimpleDateFormat("yyMMddHHmmss");
            date = formatter.format(currentTime);
            qxDataService.insertQxData(data, userkey, date);
        }

    }
    @RequestMapping("/chuanshujv.html")
    public void chuanshujv() throws Exception {
            ExcelController excelController = new ExcelController();
       List<String> list =  excelController.excel("C:\\Users\\zth-1\\Downloads\\asd\\20160726010.xls");
        for (int i = 0; i <list.size() ; i++) {
                String data = null;
            data= list.get(i);
            String[] datas = data.split(",");
            String date = datas[0];
            date=date.replace(" ","");
            date=date.replace(":","");
            date=date.replace("-","");
            date= date.substring(2);
            String userkey ="20160726010";
            data = data.substring(20);
            System.out.println(data);
            qxDataService.insertQxData(data, userkey, date);
        }
    }

}
